﻿// HSS.Interlink.UI.CustomEvents.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.html)
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2012
// ----------------------------------------------------------------------------
// File:       CustomEvents.cs
// Author:     HSS\gbanta
// Created:    01/17/2012
// Modified:   08/18/2012
// ----------------------------------------------------------------------------
namespace HSS.Interlink.UI
{
	#region Using Directives
	using System;
	using System.ComponentModel;
#if SILVERLIGHT
	using System.Windows.Browser;
#endif
	#endregion

	#region Event Args

	#region StateChangedEventArgs
	/// <summary>
	/// A custom event args for use with Javascript integration.
	/// </summary>
	[ScriptableType]
	public sealed class StateChangedEventArgs : EventArgs
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="newState">The new state.</param>
		public StateChangedEventArgs(string newState)
		{
			this.State = newState;
		}

		/// <summary>
		/// Gets the new state.
		/// </summary>
		[ScriptableMember]
		public string State
		{
			get;
			private set;
		}
	}
	#endregion

	#region GetMetadataEventArgs
	/// <summary>
	/// Event arguments for the GetMetadata event.
	/// </summary>
	public sealed class GetMetadataEventArgs : EventArgs
	{
		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="fileName">The name of the file to provide the metadata for.</param>
		public GetMetadataEventArgs(string fileName)
		{
			this.FileName = fileName;
			this.Metadata = string.Empty;
		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets the name of the file to provide the metadata for.
		/// </summary>
		public string FileName { get; private set; }
		/// <summary>
		/// A property to provide the metadata for an <see cref="UploadFile"/>.
		/// </summary>
		public string Metadata { get; set; }
		#endregion
	}
	#endregion

	#region ViewFileDetailsEventArgs
	/// <summary>
	/// The Event Arguments for the ViewFileDetails Event.
	/// </summary>
	public sealed class ViewFileDetailsEventArgs : EventArgs
	{
		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="file">The <see cref="UploadFile"/> to view the details of.</param>
		public ViewFileDetailsEventArgs(UploadFile file)
		{
			this.File = file;
		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets the <see cref="UploadFile"/> to view the details of.
		/// </summary>
		public UploadFile File
		{
			get;
			private set;
		}
		#endregion
	}
	#endregion

	#region UploadManagerProgressEventArgs
	/// <summary>
	/// Provides data for the <see cref="UploadManager.UploadProgressChanged"/> event for the <see cref="UploadManager"/>.
	/// </summary>
	[ScriptableType]
	public sealed class UploadManagerProgressEventArgs : EventArgs
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="progressPercentage">The percentage of an asynchronous operation that has been completed.</param>
		/// <param name="userToken">The async operation user token.</param>
		/// <param name="bytesSent">The number of bytes sent.</param>
		/// <param name="totalBytesToSend">The total number of bytes to send.</param>
		internal UploadManagerProgressEventArgs(int progressPercentage, object userToken, long bytesSent, long totalBytesToSend)
		{
			this.ProgressPercentage = progressPercentage;
			this.UserState = userToken;
			this.BytesSent = bytesSent;
			this.TotalBytesToSend = totalBytesToSend;
		}

		/// <summary>
		/// Gets the percentage of an asynchronous operation that has been completed.
		/// </summary>
		[ScriptableMember]
		public int ProgressPercentage { get; private set; }
		/// <summary>
		/// Gets the number of bytes sent.
		/// </summary>
		/// <returns>An System.Int64 value that indicates the number of bytes sent.</returns>
		[ScriptableMember]
		public long BytesSent { get; private set; }
		/// <summary>
		/// Gets the total number of bytes to send.
		/// </summary>
		/// <returns>An System.Int64 value that indicates the number of bytes that will be sent.</returns>
		[ScriptableMember]
		public long TotalBytesToSend { get; private set; }
		/// <summary>
		/// Gets the number of bytes remaining.
		/// </summary>
		[ScriptableMember]
		public long BytesRemaining
		{
			get
			{
				if (!_bytesRemaining.HasValue)
					_bytesRemaining = TotalBytesToSend - BytesSent;
				return _bytesRemaining.Value;
			}
		} long? _bytesRemaining;
		/// <summary>
		/// Gets a unique user state.
		/// </summary>
		[ScriptableMember]
		public object UserState { get; private set; }
	}
	#endregion

	#region UploadManagerFileChangedEventArgs
	/// <summary>
	/// The event args for when a IUploadFile is added, removed or has changes.
	/// </summary>
	[ScriptableType]
	public class UploadManagerFileChangedEventArgs : EventArgs
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="file">The <see cref="UploadFile"/> instance.</param>
		/// <param name="propertyName">The name of the property that changed.</param>
		public UploadManagerFileChangedEventArgs(UploadFile file, string propertyName)
		{
			this.File = file;
			this.PropertyName = propertyName;
		}

		/// <summary>
		/// Gets the file that was added, removed or changed.
		/// </summary>
		[ScriptableMember]
		public UploadFile File
		{
			get;
			private set;
		}
		/// <summary>
		/// Gets the name of the property that changed.
		/// </summary>
		[ScriptableMember]
		public string PropertyName { get; private set; }
	}
	#endregion

	#endregion
}